package main

import (
	"io/fs"
	"log"
	"os"
	"path/filepath"
	"strings"
)

// 指定路径，递归将文件夹下的所有ok文件重命名为snt文件
func main() {
	if len(os.Args) != 2 {
		log.Fatalln("请输入路径参数, 示例: ok2snt d:/share/send")
	}
	path := os.Args[1]
	log.Println("执行开始, 处理路径:", path)

	okCount := 0

	filepath.Walk(path, func(path string, info fs.FileInfo, err error) error {
		if err != nil {
			return err
		}

		if info.IsDir() || !strings.HasSuffix(info.Name(), ".ok") {
			return nil
		}

		newPath := strings.TrimSuffix(path, ".ok") + ".snt"
		err = os.Rename(path, newPath)
		if err != nil {
			log.Println("重命名错误: ", newPath, ", 错误: ", err)
			return err
		}
		log.Println("重命名完成: ", path, " ==> ", newPath)
		okCount++
		return nil
	})

	log.Println("执行完毕, 重命名成功个数: ", okCount)
}
